﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Collections;
namespace DAO
{
    public class BangGiaVeDAO
    {
         DataTable dt;
        List<string> dsThamSo;
        ArrayList dsGiaTri;
       
        
        public BangGiaVeDAO()
        {
            dt = new DataTable();
            dsThamSo = new List<string>();
            dsGiaTri = new ArrayList();
            
        }
        public void CapNhatSoCho(string maChuyenBay,int loaiVe)
        {
            string sql = " update BangGiaVe set soChoHienTai += 1 where ID_loaiVe=" + loaiVe + " and ID_chuyenBay = '" + maChuyenBay+"'";
            DataProvider.ExecuteNoneQuery(sql);
        }
        public float layGiaVe(string maChuyenBay, int loaiVe)
        {
            dsThamSo.Add("@maChuyenBay");
            dsGiaTri.Add(maChuyenBay);
            dsThamSo.Add("@loaiVe");
            dsGiaTri.Add(loaiVe);
            dt = DataProvider.ExecuteStoreProc("sp_layGiaVe", dsThamSo, dsGiaTri);
            float giaVe = 0;
            if (dt.Rows.Count == 1)
            {
                giaVe = float.Parse(dt.Rows[0]["giaVe"].ToString());
            }
            return giaVe;
        }
        public int themBangGiaVe(string maChuyenBay, int soChoHang1, int soChoHang2, int soChoHang3, float giaVeHangThuongGia, float giaVeHangPhoThong, float giaVeHangTietKiem)
        {
            int n,n1,n2 ;
            n = n1 = n2  = 0;
             
            string sql = "insert into BangGiaVe values(1,'"+maChuyenBay+"',"+giaVeHangThuongGia+",'SGD',"+soChoHang1+","+soChoHang1+")";
            n = DataProvider.ExecuteNoneQuery(sql);
            string sql1 = "insert into BangGiaVe values(2,'" + maChuyenBay + "'," + giaVeHangPhoThong + ",'SGD'," + soChoHang2 + "," + soChoHang2 + ")";
            n1 = DataProvider.ExecuteNoneQuery(sql1);
            string sql2 = "insert into BangGiaVe values(3,'" + maChuyenBay + "'," + giaVeHangTietKiem + ",'SGD'," + soChoHang3 + "," + soChoHang3 + ")";
            n2 = DataProvider.ExecuteNoneQuery(sql2);
            return n + n1 + n2;

        }
    }
}
